Skip to content

Read gvfs.* booleans with git when the environment changes config - #2156

Closed
Tyrie Vella (tyrielv) wants to merge 1 commit into
microsoft:masterfrom
tyrielv:tyrielv/libgit2-config-env-fallback
Closed

Tyrie Vella (tyrielv) wants to merge 1 commit into
microsoft:masterfrom
tyrielv:tyrielv/libgit2-config-env-fallback

Conversation

@tyrielv

Copy link
Copy Markdown
Contributor

Problem and Context

libgit2 does not read the config that GIT_CONFIG_GLOBAL, GIT_CONFIG_SYSTEM, GIT_CONFIG_NOSYSTEM, GIT_CONFIG, GIT_CONFIG_COUNT, or GIT_CONFIG_PARAMETERS select or supply. RetryConfig already detects these variables with LibGit2Repo.EnvironmentChangesGitConfig() and reads its settings with git.exe. The boolean gvfs.* settings did not. They read the user's real config and ignored the value from the environment.

This affects gvfs.trust-pack-indexes, gvfs.prefetch-offload, gvfs.background-cache-auth, gvfs.mount-progress, and gvfs.show-hydration-status. For example, CloneNetworkTests sets gvfs.trust-pack-indexes through GIT_CONFIG_GLOBAL. The clone ignores that value. The test passes only because its value matches the default.

Changes

  • When EnvironmentChangesGitConfig() is true, read boolean settings with git config --type=bool. Git normalizes the value, exits with 1 when the key is unset, and fails when the value is not a boolean. A failed read logs a warning and uses the default, as the libgit2 read does.
  • Add the LibGit2Repo.TryReadConfigBoolWithGit delegate. The static LibGit2Repo.GetConfigBoolOrDefault now requires it, so a new caller cannot skip the git route.
  • Parse the git output in LibGit2Repo. GVFS.Hooks compiles LibGit2Repo.cs without GitProcess, so the hook and the other processes share one parser.
  • Add GitProcess.TryGetBoolFromConfig.
  • Give LibGit2RepoInvoker an optional git reader. GitRepo supplies one from its enlistment. This covers PrefetchStep, PackfileMaintenanceStep, and GitStatusCache.
  • Pass a git reader from CloneVerb, PrefetchVerb, InProcessMount, and GVFS.Hooks. The hook runs git from PATH in the current directory, as its alias check already does. gvfs.mount-progress now uses the static helper instead of its own LibGit2Repo read.
  • When the environment does not change config, the reads still use libgit2. The git route adds one git.exe process for each read only in the affected environments.
  • Add unit tests that verify the git route, the libgit2 route, an unset key, a failed git read, the output parser, and the git config --type=bool command line.

libgit2 does not read the config that GIT_CONFIG_GLOBAL, GIT_CONFIG_SYSTEM,
GIT_CONFIG_NOSYSTEM, GIT_CONFIG, GIT_CONFIG_COUNT, or GIT_CONFIG_PARAMETERS
select or supply. RetryConfig already reads its settings with git.exe in
that case. The boolean gvfs.* settings did not. For example,
gvfs.trust-pack-indexes, gvfs.prefetch-offload, and
gvfs.show-hydration-status ignored a value that came from one of these
variables, and the read used the user's real config instead.

When LibGit2Repo.EnvironmentChangesGitConfig() is true, read these
settings with "git config --type=bool". Git normalizes the value, exits
with 1 when the key is unset, and fails when the value is not a boolean.

- Add the LibGit2Repo.TryReadConfigBoolWithGit delegate and make the
  static LibGit2Repo.GetConfigBoolOrDefault require it. Parse the git
  output in LibGit2Repo so that GVFS.Hooks, which compiles LibGit2Repo.cs
  without GitProcess, can share the parser.
- Add GitProcess.TryGetBoolFromConfig.
- Give LibGit2RepoInvoker an optional git reader. GitRepo supplies one
  from its enlistment.
- Pass a git reader from CloneVerb, PrefetchVerb, InProcessMount, and
  GVFS.Hooks. Read gvfs.mount-progress through the static helper.
- Add unit tests for the git route, the libgit2 route, an unset key, a
  failed git read, the output parser, and the git command line.

Assisted-by: Claude Opus 5.5
Signed-off-by: Tyrie Vella <tyrielv@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant